
--83
--82
--81
--80
--79

Declare @CEUserId bigint
Declare @ManYear int
Declare @RegYear int
Declare @CarMakeId int
Declare @CarModelId int
Declare @NCD int
Declare @CoverageType int
Declare @IsClaim bit
Declare @IsOffDriveCom bit
Declare @IsAddDriver bit

Select @CEUserId = 79
Select @ManYear = 2008
Select @RegYear = 2009
Select @CarMakeId = 0
Select @CarModelId = 0
Select @NCD = 10
Select @CoverageType = 0
Select @IsClaim = 0
Select @IsOffDriveCom = 0
Select @IsAddDriver = 0

Declare curCarDetail cursor for
Select top 1 CarMakeId, CarModelId from tblCarModelInfo Order By NewID()
--Select MAX(CECArId) from tblCarDetail -- 269
--Select MAX(CECarPolicyID) from tblCarPolicy -- 263
--Select top 100 * from tblCarClaimHistory Order By ModifiedDate DESC

Open curCarDetail 
		fetch next from curCarDetail into @CarMakeId, @CarModelId
		WHILE (@@fetch_status <> -1)
		BEGIN
			INSERT INTO tblCarDetail(CarMakeId, CarModelId, ManufactYear, RegYear, RefCEUserId, Status)
			Select @CarMakeId as CarMakeId, @CarModelId as CarModelId, @ManYear as ManYear, @RegYear as RegYear, @CEUserId as RefCEUserId, 'CarReport' as [Status]
			
			INSERT INTO tblCarPolicy(CECarId, TypeOfCoverage, CoverageCommenceDate, NCDPercent, IsClaimLastThreeYear, IsOffDriveCom, IsAddDriver, RefCEUserId)
			Select SCOPE_IDENTITY() as CECarId, @CoverageType as TypeOfCoverage, GETDATE() as CoverageCommenceDate, @NCD NCDPercent, @IsClaim As IsClaimLastThreeYear, @IsOffDriveCom As IsOffDriveCom, @IsAddDriver as IsAddDriver, @CEUserId as RefCEUserId
			fetch next from curCarDetail into @CarMakeId, @CarModelId
			
			if @IsClaim = 1 
			BEGIN
				INSERT tblCarClaimHistory(CECarId, NOCLast3, NOCLast3Value, NOCLast2, NOCLast2Value, NOCLast1, NOCLast1Value, RefCEUserId)
				Select SCOPE_IDENTITY() as CECarId, 1 as NoCLast3, 1000 as NOCLast3Value, 0 as NoCLast2, 0 as NOCLast2Value, 0 as NoCLast1, 0 as NOCLast1Value, @CEUserId as RefCEUserId 
			END
		END
	Close curCarDetail
	Deallocate curCarDetail
	
Declare curCarPolicy cursor for
Select top 100 CarMakeId, CarModelId, @ManYear, @RegYear, 0, 0, @CEUserId from tblCarModelInfo Order By NewID()


select top 5 * from tblCEUser Order By ModifiedDate desc
select top 1 * from tblCarDetail Order By ModifiedDate desc
select top 1 * from tblCarPolicy Where IsClaimLastThreeYear = 1 Order By ModifiedDate desc
 